<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>弹出数组最后一个单元（出栈）</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.array-pad.html">« array_pad</a></li>
      <li style="float: right;"><a href="function.array-product.html">array_product »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.array.html">数组 函数</a></li>
    <li>弹出数组最后一个单元（出栈）</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.array-pop" class="refentry">
   <div class="refnamediv">
    <h1 class="refname">array_pop</h1>
    <p class="verinfo">(PHP 4, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">array_pop</span> &mdash; <span class="dc-title">弹出数组最后一个单元（出栈）</span></p>

   </div>
 <div class="refsect1 description" id="refsect1-function.array-pop-description">
  <h3 class="title">说明</h3>
 <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>array_pop</strong></span>(<span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$array</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>

    <p class="para rdfs-comment">
     <span class="function"><strong>array_pop()</strong></span> 弹出并返回
     <code class="parameter">array</code> 最后一个元素的值，并将
     <code class="parameter">array</code> 的长度减一。
    </p>
    <blockquote class="note"><p><strong class="note">注意</strong>: <span class="simpara">使用此函数后会重置（<span class="function"><a href="function.reset.html" class="function">reset()</a></span>）<span class="type">array</span>
指针。</span></p></blockquote>
   </div>


 <div class="refsect1 parameters" id="refsect1-function.array-pop-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">array</code></dt>

     <dd>

      <p class="para">
       需要弹出栈的数组。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.array-pop-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   返回 <code class="parameter">array</code> 最后一个元素的值。如果 <code class="parameter">array</code> 是空，将会返回 <strong><code>null</code></strong> 。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.array-pop-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-4942">
    <p><strong>示例 #1 <span class="function"><strong>array_pop()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$stack&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #DD0000">"orange"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"banana"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"apple"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"raspberry"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$fruit&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">array_pop</span><span style="color: #007700">(</span><span style="color: #0000BB">$stack</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$stack</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>
     经过此操作后，<var class="varname">$stack</var> 将只有 3 个单元：
    </p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; orange
    [1] =&gt; banana
    [2] =&gt; apple
)
</pre></div>
    </div>
    <div class="example-contents"><p>
     并且 <code class="literal">raspberry</code> 将被赋给 <var class="varname">$fruit</var>。
    </p></div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.array-pop-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="function.array-push.html" class="function" rel="rdfs-seeAlso">array_push()</a> - 将一个或多个单元压入数组的末尾（入栈）</span></li>
    <li class="member"><span class="function"><a href="function.array-shift.html" class="function" rel="rdfs-seeAlso">array_shift()</a> - 将数组开头的单元移出数组</span></li>
    <li class="member"><span class="function"><a href="function.array-unshift.html" class="function" rel="rdfs-seeAlso">array_unshift()</a> - 在数组开头插入一个或多个单元</span></li>
   </ul>
  </p>
 </div>

  </div></div></div></body></html>